package com.miniapp.core.utils;


import com.miniapp.common.gen.domain.PaicFtiPolicy;
import com.miniapp.common.gen.domain.PaicFtiRate;
import com.miniapp.common.gen.domain.PaicFtiRateExample;
import com.miniapp.common.gen.mapper.PaicFtiPolicyMapper;
import com.miniapp.common.gen.mapper.PaicFtiRateMapper;
import com.miniapp.common.utils.MoneyUtil;
import com.miniapp.common.utils.StringUtils;
import com.miniapp.core.domain.paicfti.*;
import org.apache.commons.collections4.CollectionUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class PaicFtiInputInsuranceInfoUtils {

    private Logger logger = LoggerFactory.getLogger(PaicFtiInputInsuranceInfoUtils.class);

    @Autowired
    private PaicLoginUtil paicLoginUtil;

    /**
     * 录入投保信息
     * @param paicFtiInsureParam
     * @param insurePageChromeDriver
     */
    public void inputInsuranceInfo(PaicFtiInsureParam paicFtiInsureParam, ChromeDriver insurePageChromeDriver)  {
        //1、刷新页面
        logger.info("==========进入投保页面，刷新一下页面==========");
        String currentUrl = insurePageChromeDriver.getCurrentUrl();
        if(currentUrl.contains("https://cargo.pa18.com/cargo/#/document-info?quotationNo=")){
            insurePageChromeDriver.navigate().refresh();
        }else {
            String account = paicFtiInsureParam.getAccount();
            String password = paicFtiInsureParam.getPassword();
            String uniqueId = paicFtiInsureParam.getUniqueId();
            insurePageChromeDriver = paicLoginUtil.getInsurePageChromeDriver(account,password,uniqueId);

        }
        //等待十秒钟看
        WebDriverWait webDriverWait = new WebDriverWait(insurePageChromeDriver,10);
        webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[1]/td[2]/div/div/div/label")));

        //判断当前页面是否有方案元素，有说明页面加载完成
//        for (int i = 0; i < 20; i++) {
//            ThreadUtils.threadSleep(200);
//            logger.info("【【【【【【【【投保页面第"+(i+1)+"次获取方案信息】】】】】】】");
//            List<WebElement> webElementList = insurePageChromeDriver.findElementsByXPath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[1]/td[2]/div/div/div/label");
//            if(CollectionUtils.isNotEmpty(webElementList)){
//                break;
//            }else {
//                ThreadUtils.threadSleep(300);
//            }
//        }


        //2、选择方案
        logger.info("==========开始选择投保方案==========");
        this.selectProductType(paicFtiInsureParam, insurePageChromeDriver);
        logger.info("==========选择投保方案完成==========");

        //3、输入被保人信息
        logger.info("//**********输入被保人信息//**********");
        inputPaicFtiInsurant(paicFtiInsureParam, insurePageChromeDriver);
        logger.info("//**********被保人信息输入完成//**********");

        //4、输入货物信息
        logger.info("==========输入货物信息==========");
        inputPaicFtiCargo(paicFtiInsureParam, insurePageChromeDriver);
        logger.info("==========货物信息输入完成==========");

        //5、运输信息
        logger.info("**********开始输入运输信息**********");
        inputPaicFtiTransport(paicFtiInsureParam, insurePageChromeDriver);
        logger.info("**********运输信息输入完成**********");


        //6、保险信息
        logger.info("==========输入保险信息==========");
        inputPaicFtiInsurance(paicFtiInsureParam,insurePageChromeDriver);
        logger.info("==========保险信息如无完成==========");



        //7、阅读同意
        logger.info("**********开始点击阅读同意**********");
        WebElement yuedutongyi = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[8]/div[3]/span[1]/label/a");
        //滚动至元素可见
        insurePageChromeDriver.executeScript("arguments[0].scrollIntoView(true);",yuedutongyi);
        yuedutongyi.click();
        logger.info("**********阅读同意已经点击**********");

    }

    /**
     * 1、选择产品方案
     * @param paicFtiInsureParam
     * @param insurePageChromeDriver
     */
    public void selectProductType(PaicFtiInsureParam paicFtiInsureParam, ChromeDriver insurePageChromeDriver){
        //产品方案
        String productType = paicFtiInsureParam.getProductType();
        WebElement elementByXPath = null;
        ThreadUtils.threadSleep(10);
        if("TC001".equals(productType)){
            //方案一：冷链冷冻含失温
            logger.info("选择方案：冷链冷冻含失温");
            elementByXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[1]/td[2]/div/div/div/label");
        }else if("TC002".equals(productType)){
            //方案二：冷链冷藏含失温
            logger.info("选择方案：冷链冷藏含失温");
            elementByXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[2]/td[2]/div/div/div/label");
        }else if("TC003".equals(productType)){
            //方案三：冷链不含失温
            logger.info("选择方案：冷链不含失温");
            elementByXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[3]/td[2]/div/div/div/label");
        }else if("TC004".equals(productType)){
            //方案四：基本险
            logger.info("选择方案：基本险");
            elementByXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[4]/td[2]/div/div/div/label");
        }else if("TC005".equals(productType)){
            //方案五：综合险
            logger.info("选择方案：综合险");
            elementByXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[1]/div/div/div[2]/div/div[2]/table/tbody/tr[5]/td[2]/div/div/div/label");
        }
        elementByXPath.click();

    }

    /**
     * 2、输入被保人信息
     * @param paicFtiInsureParam
     * @param insurePageChromeDriver
     */
    public void inputPaicFtiInsurant(PaicFtiInsureParam paicFtiInsureParam, ChromeDriver insurePageChromeDriver){

//        ThreadUtils.threadSleep(500);
//        WebElement toubaoren = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[3]/div[1]/div/div[1]/div/input");
//        toubaoren.clear();
//        toubaoren.sendKeys("倪先生");
//        ThreadUtils.threadSleep(500);
//        toubaoren.clear();
//        WebElement lianxidianhua = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[3]/div[2]/div/div[1]/div/input");
//        lianxidianhua.sendKeys("0000000");



        //等待十秒钟看
        WebDriverWait webDriverWait = new WebDriverWait(insurePageChromeDriver,20);
        webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[5]/div[1]/div/div/label[2]")));



        PaicFtiInsurantParam paicFtiInsurant = paicFtiInsureParam.getPaicFtiInsurant();
        String customerType = paicFtiInsurant.getCustomerType();
        //001团体，002个人
        if("002".equals(customerType)){
            ThreadUtils.threadSleep(500);
            logger.info("选择被保人类型：个人");
            WebElement gerenElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[5]/div[1]/div/div/label[2]");
            gerenElement.click();
        }else {
            logger.info("被保人类型团体不用操作");
        }
        ThreadUtils.threadSleep(500);
        String customerName = paicFtiInsurant.getCustomerName();
        logger.info("开始录入被保险人名称："+customerName);
        String insuranceNameInputXpath ="//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[4]/div[1]/div/div/div/div/div/div/input";
        WebElement insuranceNameInput = PaicFtiChromeDriverUtils.waitWebElementByXPath(insurePageChromeDriver, insuranceNameInputXpath, 20);
//        WebElement 被保险人名称 = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[4]/div[1]/div/div/div/div/div/div/input");
        insuranceNameInput.clear();
        insuranceNameInput.sendKeys(customerName);
        logger.info("被保险人名称录入完成："+customerName);

        for (int i = 0; i < 4; i++) {
            ThreadUtils.threadSleep(500);
            //被保人如果能查询到，就选择第一个
            List<WebElement> customerNameElementList = insurePageChromeDriver.findElementsByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[4]/div[1]/div/div/div/div/ul/div[1]/div/li");
            if(CollectionUtils.isNotEmpty(customerNameElementList)){
                customerNameElementList.get(0).click();
                break;
            }
        }

        String customerIdNum = paicFtiInsurant.getCustomerIdNum();
        logger.info("开始输入证件号码："+customerIdNum);
        WebElement 证件号码 = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[4]/div[3]/div/div[1]/div/input");
        证件号码.clear();
        证件号码.sendKeys(customerIdNum);
        logger.info("证件号码输入完成："+customerIdNum);

        String contactPerson = paicFtiInsurant.getContactPerson();
        logger.info("开始输入联系人姓名："+contactPerson);
        WebElement 联系人 = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[5]/div[2]/div/div/div/input");
        联系人.clear();
        联系人.sendKeys(contactPerson);
        logger.info("联系人姓名输入完成："+contactPerson);

        String contactPonhe = paicFtiInsurant.getContactPonhe();
        logger.info("开始输入联系电话："+contactPonhe);
        WebElement 联系电话 = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[5]/div[3]/div/div/div/input");
        联系电话.clear();
        联系电话.sendKeys(contactPonhe);
        logger.info("联系电话输入完成："+contactPonhe);

        String contactAddress = paicFtiInsurant.getContactAddress();
        logger.info("开始输入联系地址："+contactAddress);
        WebElement 联系地址 = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[1]/form/div[5]/div[4]/div/div/div/input");
        联系地址.clear();
        联系地址.sendKeys(contactAddress);
        logger.info("联系地址输入完成："+contactAddress);
    }

    /**
     * 3、录入货物信息
     * @param paicFtiInsureParam
     * @param insurePageChromeDriver
     * @return
     */
    public void inputPaicFtiCargo(PaicFtiInsureParam paicFtiInsureParam, ChromeDriver insurePageChromeDriver){
        PaicFtiCargo paicFtiCargo = paicFtiInsureParam.getPaicFtiCargo();
        String cargoType = paicFtiCargo.getCargoType();
        String packingType = paicFtiCargo.getPackingType();
        String cargoMessage = paicFtiCargo.getCargoMessage();

        //1、货物类型
        logger.info("开始选择货物类型");
        ThreadUtils.threadSleep(100);
        //滚动至元素可见
        logger.info("货物类型，滚动至元素可见");
        WebElement cargoTypeElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[1]/div");
        insurePageChromeDriver.executeScript("arguments[0].scrollIntoView(true);",cargoTypeElement);
        ThreadUtils.threadSleep(100);
        cargoTypeElement.click();

        String cargoTypeXpath = getCargoTypeXpath(cargoType);
        ThreadUtils.threadSleep(100);
        WebElement cargoTypeXpathElement = insurePageChromeDriver.findElementByXPath(cargoTypeXpath);
        ThreadUtils.threadSleep(100);
        cargoTypeXpathElement.click();
        logger.info("货物类型选择完毕");

        //2、包装方式
        logger.info("开始选择包装方式："+packingType);
        WebElement packingTypeElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[1]/div/input");
        packingTypeElement.click();
        String packingTypeXpath = getPackingTypeXpath(packingType);
        WebElement packingTypeXpahtElement = insurePageChromeDriver.findElementByXPath(packingTypeXpath);
        packingTypeXpahtElement.click();
        logger.info("包装方式选择完成");

        //3、货物标的描述及数量
        logger.info("开始输入货物标的描述及数量");
        WebElement cargoMessageElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[3]/div/div/div/div/div/div/div[1]/div/textarea");
        cargoMessageElement.clear();
        cargoMessageElement.sendKeys(cargoMessage);
        logger.info("货物标的描述及数量输入完成");
    }

    /**
     * 4、录入运输信息
     * @return
     */
    public void inputPaicFtiTransport(PaicFtiInsureParam paicFtiInsureParam, ChromeDriver insurePageChromeDriver){
        PaicFtiTransport paicFtiTransport = paicFtiInsureParam.getPaicFtiTransport();
        //发票号码
        String invoiceNumber = paicFtiTransport.getInvoiceNumber();
        logger.info("开始录入发票号码："+invoiceNumber);
        if(StringUtils.isNotBlank(invoiceNumber)){
            WebElement invoiceNumberXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[3]/form/div[2]/div[1]/div/div/div/div/div/input");
            invoiceNumberXPath.clear();
            invoiceNumberXPath.sendKeys(invoiceNumber);
        }
        logger.info("发票号码录入完成："+invoiceNumber);

        //提/运单号
        String waybillNumber = paicFtiTransport.getWaybillNumber();
        logger.info("开始录入运单号码："+waybillNumber);
        if(StringUtils.isNotBlank(waybillNumber)){
            WebElement waybillNumberXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[3]/form/div[2]/div[2]/div/div/div/div/div/input");
            waybillNumberXPath.clear();
            waybillNumberXPath.sendKeys(waybillNumber);
        }
        logger.info("运单号码录入完成："+waybillNumber);

        //车牌号
        ThreadUtils.threadSleep(200);
        String licensePlateNumber = paicFtiTransport.getLicensePlateNumber();
        logger.info("开始录入车牌号码："+licensePlateNumber);
        WebElement licensePlateNumberXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[3]/form/div[2]/div[3]/div/div/div/div/div/input");
        licensePlateNumberXPath.clear();
        licensePlateNumberXPath.sendKeys(licensePlateNumber);
        logger.info("车牌号码录入完成："+licensePlateNumber);

        //起运地描述
        ThreadUtils.threadSleep(200);
        String placeOfDispatch = paicFtiTransport.getPlaceOfDispatch();
        logger.info("开始录入起运地描述："+placeOfDispatch);
        WebElement placeOfDispatchXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[3]/form/div[3]/div[3]/div/div/div/div/textarea");
        placeOfDispatchXPath.clear();
        placeOfDispatchXPath.sendKeys(placeOfDispatch);
        logger.info("起运地描述录入完成："+placeOfDispatch);

        //目的地描述
        ThreadUtils.threadSleep(200);
        String destination = paicFtiTransport.getDestination();
        logger.info("开始录入目的地描述："+destination);
        WebElement elementByXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[3]/form/div[4]/div[3]/div/div/div/div/textarea");
        elementByXPath.clear();
        elementByXPath.sendKeys(destination);
        logger.info("目的地描述录入完成："+destination);

        //起运时间
        ThreadUtils.threadSleep(200);
        logger.info("开始录入起运时间");
        String shippingTime = paicFtiTransport.getShippingTime();
        WebElement shippingTimeXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[3]/form/div[5]/div[2]/div/div[1]/div/div/div[1]/div/div/input");
        for (int i = 0; i < 20; i++) {
            shippingTimeXPath.sendKeys(Keys.BACK_SPACE);
        }
        shippingTimeXPath.sendKeys(shippingTime);
        logger.info("起运时间录入完成");



    }

    /**
     * 5、录入保险信息
     * @param paicFtiInsureParam
     * @param insurePageChromeDriver
     * @return
     */
    public void inputPaicFtiInsurance(PaicFtiInsureParam paicFtiInsureParam, ChromeDriver insurePageChromeDriver){
        PaicFtiInsurance paicFtiInsurance = paicFtiInsureParam.getPaicFtiInsurance();
        String productType = paicFtiInsureParam.getProductType();
        Integer insuranceAmount = paicFtiInsurance.getInsuranceAmount();
        BigDecimal insuranceAmountFen = BigDecimal.valueOf(insuranceAmount);
        BigDecimal insuranceAmountYuan = insuranceAmountFen.divide(new BigDecimal(100));
        logger.info("保险金额转换成元："+insuranceAmountYuan.toString());




        logger.info("开始录入发票金额");
        WebElement insuranceAmountXPath = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[4]/form/div[5]/div[1]/div[1]/div/div[1]/div/div/div/input");
        logger.info("获取到发票金额输入框");
        insuranceAmountXPath.sendKeys(insuranceAmountYuan.toString());
        logger.info("发票金额录入完成");

        //点击空白处 自动计算保费
        ThreadUtils.threadSleep(300);
        logger.info("点击空白处自动计算保额、保费等信息");
        WebElement kongbai_1 = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[5]/form/div[1]");
        kongbai_1.click();
        logger.info("空白处点击完成");
        ThreadUtils.threadSleep(1000);



//        ThreadUtils.threadSleep(300);
//        logger.info("开始输入费率");
//        WebElement rateElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[4]/form/div[5]/div[2]/div[1]/div/div/div/div/div[1]/input");
//        rateElement.clear();
//        String rate = getRate(productType);
//        rateElement.sendKeys(rate);



        //点击空白处 自动计算保费
//        ThreadUtils.threadSleep(300);
//        logger.info("点击空白处自动计算保额、保费等信息");
//        WebElement kongbai = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[5]/form/div[1]");
//        kongbai.click();
//        logger.info("空白处点击完成");
//        ThreadUtils.threadSleep(1000);

        //获取保额
        WebElement amountElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[4]/form/div[5]/div[1]/div[2]/div/div[1]/div/div/div/input");
        String amount = amountElement.getAttribute("value");
        logger.info("自动计算出来的保险金额为："+amount);

        WebElement baofeiElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[4]/form/div[5]/div[2]/div[3]/div/div[1]/div/div/div/input");
        String baofei = baofeiElement.getAttribute("value");
        logger.info("自动计算出来的保费为："+baofei);

        if(StringUtils.isNotBlank(baofei)){
            try {
                String baofeiFen = MoneyUtil.moneyMul(baofei, "100");
                int baofeiFenInt = Double.valueOf(baofeiFen).intValue();
                logger.info("自动计算出来的保费（分）为："+baofeiFenInt);
                //页面保费入库
                PaicFtiPolicy paicFtiPolicy = PaicFtiUtils.localPaicFtiPolicy.get();
                paicFtiPolicy.setPagePremium(baofeiFenInt);
                paicFtiPolicyMapper.updateByPrimaryKeySelective(paicFtiPolicy);
                logger.info("页面上的保费入库成功");
            }catch (Exception e){
                logger.info("页面上的保费入库失败{}",e.getMessage());
            }
        }
        ThreadUtils.threadSleep(500);
        try {
            logger.info("开始获取页面上的费率");
            WebElement newRateElement = insurePageChromeDriver.findElementByXPath("//*[@id=\"mainSection\"]/div/section/div[2]/div/div[4]/form/div[5]/div[2]/div[1]/div/div/div/div/div[1]/input");
            String pageRate = newRateElement.getAttribute("value");
            logger.info("获取页面上的费率为：{}",pageRate);
            PaicFtiPolicy paicFtiPolicy = PaicFtiUtils.localPaicFtiPolicy.get();
            paicFtiPolicy.setPageRate(pageRate);
            paicFtiPolicyMapper.updateByPrimaryKeySelective(paicFtiPolicy);
            logger.info("页面上的费率入库成功");
        }catch (Exception e){
            logger.info("获取页面上的费率失败"+e.getMessage());
        }
    }


    @Autowired
    private PaicFtiRateMapper paicFtiRateMapper;
    @Autowired
    private PaicFtiPolicyMapper paicFtiPolicyMapper;

    public String getRate(String productType){
        PaicFtiRateExample paicFtiRateExample = new PaicFtiRateExample();
        paicFtiRateExample.createCriteria().andProductTypeEqualTo(productType);
        PaicFtiRate paicFtiRate = paicFtiRateMapper.selectByExample(paicFtiRateExample).get(0);
        String rate = paicFtiRate.getRate();
        return rate;
    }







    /**
     * 获取货物类型Xpath
     * @param cargoType
     * @return
     */
    public String getCargoTypeXpath(String cargoType){
        //03动、植物油、脂及其分解产品；精制的食用油脂；动、植物蜡
        //04食品；饮料、酒及醋；烟草、烟草及烟草代用品的制品
        //05矿产品
        //06化学工业及其相关工业的产品
        //07塑料及其制品；橡胶及其制品
        //08生皮、皮革、毛皮及其制品；鞍具及挽具；旅行制品、手提包及其类似容器、动物肠线（蚕胶丝除外）制品
        //09木及木制品；木炭；软木及软木制品；稻草、秸秆、针茅或其他编结材料制品；篮筐及柳条编结品
        //10木浆及其他纤维状纤维素浆；回收（废碎）纸或纸板；纸、纸板及其制品
        //11纺织原料及纺织制品
        //12鞋、帽、伞、杖、鞭及其零件；已加工的羽毛及其制品；人造花；人发制品
        //13石料、石膏、水泥、石棉、云母及 类似材料的制品；陶瓷产品；玻璃及其制品似材料的制品
        //14天然或养殖珍珠、宝石或半宝石、贵金属、包贵金属及其制品；仿首饰；硬币
        //15贱金属及其制品
        //16机器、机械器具、电气设备及其零件；录音机及放声机、电视图像、声音的录制和重放设备及其零件、附件
        //17车辆、航空器、船舶及有关运输设备
        //18光学、照相、电影、计量、检验、医疗或外科用仪器及设备、精密仪器及设备；钟表；乐器；上述物品的零件、附件疗或外科用仪器及设备、精密仪器及设备；上述物品的零件、附件
        //20杂项制品
        //
        String cargoTypeXpath = "";
        switch (cargoType) {
            case "03":
                logger.info("选择货物类型：03动、植物油、脂及其分解产品；精制的食用油脂；动、植物蜡");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[15]";
                break;
            case "04":
                logger.info("选择货物类型：04食品；饮料、酒及醋；烟草、烟草及烟草代用品的制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[11]";
                break;
            case "05":
                logger.info("选择货物类型：05矿产品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[12]";
                break;
            case "06":
                logger.info("选择货物类型：06化学工业及其相关工业的产品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[13]";
                break;
            case "07":
                logger.info("选择货物类型：07塑料及其制品；橡胶及其制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[14]";
                break;
            case "08":
                logger.info("选择货物类型：08生皮、皮革、毛皮及其制品；鞍具及挽具；旅行制品、手提包及其类似容器、动物肠线（蚕胶丝除外）制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[16]";
                break;
            case "09":
                logger.info("选择货物类型：09木及木制品；木炭；软木及软木制品；稻草、秸秆、针茅或其他编结材料制品；篮筐及柳条编结品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[17]";
                break;
            case "10":
                logger.info("选择货物类型：10木浆及其他纤维状纤维素浆；回收（废碎）纸或纸板；纸、纸板及其制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[1]";
                break;
            case "11":
                logger.info("选择货物类型：11纺织原料及纺织制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[2]";
                break;
            case "12":
                logger.info("选择货物类型：12鞋、帽、伞、杖、鞭及其零件；已加工的羽毛及其制品；人造花；人发制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[3]";
                break;
            case "13":
                logger.info("选择货物类型：13石料、石膏、水泥、石棉、云母及 类似材料的制品；陶瓷产品；玻璃及其制品似材料的制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[4]";
                break;
            case "14":
                logger.info("选择货物类型：14天然或养殖珍珠、宝石或半宝石、贵金属、包贵金属及其制品；仿首饰；硬币");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[5]";
                break;
            case "15":
                logger.info("选择货物类型：15贱金属及其制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[6]";
                break;
            case "16":
                logger.info("选择货物类型：16机器、机械器具、电气设备及其零件；录音机及放声机、电视图像、声音的录制和重放设备及其零件、附件");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[7]";
                break;
            case "17":
                logger.info("选择货物类型：17车辆、航空器、船舶及有关运输设备");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[8]";
                break;
            case "18":
                logger.info("选择货物类型：18光学、照相、电影、计量、检验、医疗或外科用仪器及设备、精密仪器及设备；钟表；乐器；上述物品的零件、附件疗或外科用仪器及设备、精密仪器及设备；上述物品的零件、附件");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[9]";
                break;
            case "20":
                logger.info("选择货物类型：20杂项制品");
                cargoTypeXpath = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[1]/div/div/div/div/div[2]/ul[2]/li[10]";
                break;
        }
        return cargoTypeXpath;

    }

    /**
     * 获取包装方式Xpath
     * @param packingType
     * @return
     */
    public String getPackingTypeXpath(String packingType){
        //01散装及托盘包装
        //02捆包状包装
        //03袋状包装
        //04箱状包装
        //05桶状包装
        //06其他形状包装
        //07裸状包装
        String packingTypeXpaht = "";
        switch (packingType){
            case "01":
                logger.info("选择包装方式：01散装及托盘包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[1]";
                break;
            case "02":
                logger.info("选择包装方式：02捆包状包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[2]";
                break;
            case "03":
                logger.info("选择包装方式：03袋状包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[3]";
                break;
            case "04":
                logger.info("选择包装方式：04箱状包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[4]";
                break;
            case "05":
                logger.info("选择包装方式：05桶状包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[5]";
                break;
            case "06":
                logger.info("选择包装方式：06其他形状包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[6]";
                break;
            case "07":
                logger.info("选择包装方式：07裸状包装");
                packingTypeXpaht = "//*[@id=\"mainSection\"]/div/section/div[2]/div/div[2]/form/div[2]/div[2]/div/div/div/div/div[2]/ul[2]/li[7]";
                break;
        }
        return packingTypeXpaht;

    }















}
